
<!--
业务提单
 -->
<template>
<div class="businessform">
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/initiatingprocess' }" v-if="isShowItem">{{process[processNumber]}}</el-breadcrumb-item>
      <span @click.stop=";" v-if="isShowSpan">{{process[processNumber]}} <i class="el-icon-arrow-right"></i></span>
      <span @click.stop=";">业务提单</span>
    </el-breadcrumb>
  </div>

  <el-tabs v-model="editableTabsValue" type="card" @tab-click="clickTabs">

    <el-tab-pane :key="item.name" v-for="(item, index) in editableTabsFixed" :label="item.title" :name="item.name">
      <business-check-form ref="checkform" @fromCheckForm="updateData" :bus="bus" :editable="editRoles.businessform_businesscheckform == 'W'" :businessformNO="saveData.businessform_no" :datas="saveData.businessform_businesscheckform"  v-if="item.name == '1'" />


      <profitCalculation ref="profit" :bus="bus"  @fromPC="updateData"  :editable="editRoles.businessform_profitcalculation == 'W'" :businessformNO="saveData.businessform_no" :datas="saveData.businessform_profitcalculation"
        v-else-if="item.name == '100'" />


      <deposit-pay ref="depositpay" :bus="bus"  @fromDP="updateData" :editable="editRoles.businessform_depositpay == 'W'"  :datas="saveData.businessform_depositpay"
        v-else-if="item.name == '101'" />

        <payment-notice ref="paymentnotice"  :bus="bus"  @fromPN="updateData"  :datas="saveData.businessform_paymentnotice" 
        :editable="editRoles.businessform_paymentnotice == 'W'"
        v-else-if="item.name == '102'" />

      <foreign-trade-contract ref="foreign" :bus="bus" @fromFC="updateData" :editable="editRoles.businessform_foreigntradecontract == 'W'" :businessformNO="saveData.businessform_no"   :datas="saveData.businessform_foreigntradecontract" v-else-if="item.name == '2'"
      />

      <pi @fromPI="updateData"  ref="pi" :bus="bus" :businessformNO="saveData.businessform_no" :editable="editRoles.businessform_pi == 'W'" :datas="saveData.businessform_pi" 
        v-else-if="item.name == '3'" />

      <template v-else-if="item.name == '4'">
          <span v-if="editRoles.businessform_domestictradecontract =='W'" slot="label"><i @click="addTab" class="operation-icon  el-icon-circle-plus"></i>{{item.title}}</span>
          <domestic-trade-contract ref="dom1"  @fromDC="updateDCData" :index="index" :bus="bus"  :editable="editRoles.businessform_domestictradecontract == 'W'"  :businessformNO="saveData.businessform_no" :datas="saveData.businessform_domestictradecontract[0]" />
        </template>

      <template v-else>
          <span v-if="editRoles.businessform_domestictradecontract =='W'"  slot="label"><i @click="removeTab(index)"  class="operation-icon  el-icon-circle-close"></i>{{item.title}}</span>

          <!-- 利用index确定当前是哪个内贸合同 index - 3 的值对应于内贸合同数组中的对应内贸合同 -->
          <domestic-trade-contract :index="index" @fromDC="updateDCData"  :bus="bus"  :editable="editRoles.businessform_domestictradecontract == 'W'"  :businessformNO="saveData.businessform_no" :datas="saveData.businessform_domestictradecontract[index - 3]" />
        </template>
    </el-tab-pane>
  </el-tabs>

  <div class="businessform-fixed">
    <fixed-form ref="fixedForm" :saveAndSend="saveAndSend" :editable="editable" :datas="allData" :sendMenus="sendMenus" processName="businessform" />
  </div>
</div>
</template>

<script>
import Vue from 'vue';
import businessCheckForm from "./components/businessCheckForm.vue";
import profitCalculation from "./components/profitCalculation.vue";
import depositPay from './components/depositPay.vue';
import paymentNotice from './components/paymentNotice.vue';
import foreignTradeContract from "./components/foreignTradeContract.vue";
import pi from "./components/pI.vue";
import domesticTradeContract from "./components/domesticTradeContract.vue";
import fixedForm from "../common/fixedForm.vue";

import { setStore, getStore } from "@/assets/js/common";

import {
  getData,
  getSendMenus,
  getOrderNumber
} from "@/server/initiatingprocess";

export default {
  created() {
    this.bus = new Vue();
    this.allData = _.cloneDeep(this.saveData);
    setStore("flow1-save-status", "unsave");
  },
  mounted() {

    //刷新浏览器时，避免重叠
    document.querySelector(".initiatingprocess  .routers-ctrl").style.zIndex =
      "-1";

    let date = new Date();
    let m = date.getMonth() + 1;
    let d = date.getDate();
    m = m < 10 ? "0" + m : m;
    d = d < 10 ? "0" + d : d;

    //获得订单编号
    getOrderNumber({
      year: date.getFullYear()
    }).then(res => {
      let businessform_no = "NO.DD" + date.getFullYear() + m + d + res;

      this.$set(this.saveData, "businessform_no", businessform_no);

      let temp = _.cloneDeep(this.allData);
      temp['businessform_no'] = businessform_no;
      this.allData = temp; 

      //获得按钮菜单数据
      getSendMenus({
        flowId: 1
      }).then(response => {
        this.sendMenus = response.data.datas[0];
      });
    });

    //判断面包屑二级路由是否可退回
    let isCreatFlow = getStore("isCreatFlow");
    this.isShowItem = !isCreatFlow ? false : true;
    this.isShowSpan = !isCreatFlow ? true : false;
  },
  beforeUpdate() {},

  updated() {
  },

  beforeRouteEnter(to, from, next) {
    next(vm => {
      let temp = vm.$children[1];
      vm.editableTabsValue = "" + to.query.tab;

      //从其他事项中跳转过来，从服务端获得数据而不是从头填写
      if (to.query.dTab) {
        //后端的查询依赖 formInstId  formServiceName
        //formInstId=2&formServiceName=business_lading
        vm.editableTabsValue = "" + to.query.dTab;

        vm.processNumber = parseInt(to.query.itemStatus);

        let params = {
          flowId: to.query.flowId,
          currNodeId: to.query.currNodeId
        };

        if (to.query.isHive == 1) {
          getData({
            formInstId: to.query.formInstId,
            formServiceName: to.query.formServiceName,
            isHive: 1
          }).then(response => {
            let data = response.data.datas[0];

            

            //对其中的字符串类型的附件名称，进行分割
            data = JSON.parse(
              JSON.stringify(data)
                .replace(/(attachedFiles)/g, function() {
                  return "useless01";
                })
                .replace(/(attachedFileList)/g, function() {
                  return "attachedFiles";
                })
                .replace(/(relationFormInst)/g, function() {
                  return "relationFormInstId";
                }),
              function(k, v) {
                if (k === "attachedFiles") {
                  if (Array.isArray(v)) {
                    return v.map(e => {
                      return {
                        name: e.realFileName,
                        status: 1,
                        id: e.id
                      };
                    });
                  } else {
                    return [];
                  }
                }

                /*
              关联订单修改了为单选
              if (k === 'relationFormInstId'){
                if (!_.isArray(v)){
                  return [];
                }
              }
              */

                if (k === "relationFormInstId") {
                  if (_.isPlainObject(v)) {
                    return [v];
                  } else {
                    return [];
                  }
                }
                return v;
              }
            );


            /**
             * 处理后端返回的空数组的情况
             */

            if (data.businessform_businesscheckform.bb_table1.length === 0){
              data.businessform_businesscheckform.bb_table1 = [{
                  bb_productName: "", 
                  bb_productFunction: "", 
                  bb_productUse: "", 
                  bb_hasBrand: "", 
                  bb_productCode: "", 
                  bb_exportCountry: "", 
                  bb_qualification: "", 
                  bb_needCheck: "", 
                  bb_otherNeed: "" 
              }];
            }


            data.businessform_domestictradecontract.forEach((e) => {
              if (e.bd_table1.length === 0){
                e.bd_table1 = [{
                  bd_table1_products: "",
                  bd_table1_description: "",
                  bd_table1_quantity: "",
                  bd_table1_price: "",
                  bd_table1_lineAmount: "",
                }];
              }
            });

            if (data.businessform_foreigntradecontract.bf_table1.length === 0) {
                data.businessform_foreigntradecontract.bf_table1 = [{
                  bf_table1_product: "",
                  bf_table1_description: "", 
                  bf_table1_price: "", 
                  bf_table1_lineAmount: "", 
                  bf_table1_quantity: "" 
                }];
            }

            if (data.businessform_pi.bp_table1.length === 0) {
                data.businessform_pi.bp_table1  = [{
                  bp_table1_products: '',
                  bp_table1_hscode: '',
                  bp_table1_description: '',
                  bp_table1_quantity: '',
                  bp_table1_price: '',
                  bp_table1_lineAmount: '',
                }];
            }


            if (data.businessform_depositpay.bdp_table1.length === 0) {
                data.businessform_depositpay.bdp_table1  = [{
                  bdp_table1_item: '',
                  bdp_table1_desc: '',
                  bdp_table1_lineAmount: '',
                }];
            }

            if (data.businessform_paymentnotice.bpn_table1.length === 0) {
                data.businessform_paymentnotice.bpn_table1  = [{
                  bpn_table1_product: '',
                  bpn_table1_description: '',
                  bpn_table1_price: '',
                  bpn_table1_quantity: '',
                  bpn_table1_lineAmount: ''
                }];
            }

            if (data.businessform_paymentnotice.bpn_table1.length === 0) {
                data.businessform_paymentnotice.bpn_table1  = [{
                  bpn_table1_product: '',
                  bpn_table1_description: '',
                  bpn_table1_price: '',
                  bpn_table1_quantity: '',
                  bpn_table1_lineAmount: ''
                }];
            }


            /***/
            for (const key in data) {
              vm.$set(vm.saveData, key,  data[key]);
            }
            /***/

            for (let i = 0,len = vm.saveData.businessform_domestictradecontract.length - 1;i < len;i++) {
              //考虑有多个内贸合同
              //根据个数决定调用 n - 1 次, 添加tab
              vm.onlyAddTab();
            }

            let approvalIndex,
              approvalFullName,
              names = [], originApprovals = _.cloneDeep(vm.saveData.originApprovals);

            if (data.role) {
              for (var prop in vm.saveData.roles) {
                vm.$set(vm.editRoles, prop,  data.role.DEFAULT);
              }

              vm.editable = data.role.DEFAULT == "W" ? true : false;
              vm.saveAndSend = vm.editable;

              let copyApprovals = _.cloneDeep(data.approvals);

              for (let i = 0; i < copyApprovals.length; i++) {
                for (var prop in originApprovals[i]) {
                  if (
                    prop != "rw" &&
                    prop != "approval_div_name" &&
                    prop != "item"
                  ) {
                    originApprovals[i][prop] =  copyApprovals[i][prop];
                  }
                }
              }

              vm.$set(vm.saveData,'originApprovals' , originApprovals);
              vm.$set(vm.saveData, 'isSalesMan', false);
            } else {
              vm.$set(vm.saveData, 'isSalesMan', true);
            }

            vm.$set(vm.saveData, "businessform_no", data.orderCode);

            //获得菜单
            getSendMenus(params).then(response => {
              vm.sendMenus = response.data.datas[0];
              vm.allData = _.cloneDeep(vm.saveData);
            });
          });
        } else {
          getData({
            formInstId: to.query.formInstId,
            formServiceName: to.query.formServiceName
          }).then(response => {
            let data = response.data.datas[0];

            /*
            let data = {
              "businessform_businesscheckform": {
                  "id": 22,
                  "createTime": 1528426522000,
                  "modifyTime": null,
                  "bb_orderCode": null,
                  "formInstId": 65,
                  "attachedFileList": [],
                  "bb_table1": [
                      {
                          "id": 24,
                          "createTime": 1528426522000,
                          "modifyTime": null,
                          "formInstId": 65,
                          "baId": 22,
                          "bb_productName": "333",
                          "bb_productUse": "看帅哥空间更何况刷卡机客户",
                          "bb_hasBrand": "上京赶考开始计划",
                          "bb_productCode": "jsgjsgkjghjgh",
                          "bb_exportCountry": "看就看花见花开",
                          "bb_qualification": "看手机观看接口",
                          "bb_needCheck": "科技计划",
                          "bb_otherNeed": "就是估计观看",
                          "bb_productFunction": "会计师控股建行卡"
                      },
                      {
                          "id": 25,
                          "createTime": 1528426522001,
                          "modifyTime": null,
                          "formInstId": 65,
                          "baId": 22,
                          "bb_productName": "333",
                          "bb_productUse": "看帅哥空间更何况刷卡机客户",
                          "bb_hasBrand": "上京赶考开始计划",
                          "bb_productCode": "jsgjsgkjghjgh",
                          "bb_exportCountry": "看就看花见花开",
                          "bb_qualification": "看手机观看接口",
                          "bb_needCheck": "科技计划",
                          "bb_otherNeed": "就是估计观看",
                          "bb_productFunction": "会计师控股建行卡"
                      }
                  ]
              },
              "businessform_foreigntradecontract": {
                  "id": 22,
                  "createTime": 1528426522000,
                  "modifyTime": null,
                  "formInstId": 65,
                  "bf_orderNumber": "xxxxxx",
                  "bf_orderDate": "2018-06-24",
                  "bf_tradeTerm": "tradeTerm",
                  "bf_shippingMarks": "shippingMarks",
                  "bf_delivery": "sigjdkjhk",
                  "bf_portOfLoad": "china",
                  "bf_portOfDestination": "USA",
                  "bf_shipment": "sgsgs",
                  "bf_downPaymentRate": "12",
                  "bf_downPayment": "13",
                  "bf_commercialInvoice": "hjxhh",
                  "bf_fullForm": "sgjskkhjkh",
                  "bf_airParcel": "",
                  "bf_fullInsurance": "ssgsgsg",
                  "bf_packageList": "sgsgsgsg",
                  "bf_originCertificate": "sgsgsgsg",
                  "bf_buy_name": "xxxx",
                  "bf_buy_address": "yyyyy",
                  "bf_buy_tel": "65757767",
                  "bf_buy_email": "hdhdgj@126.com",
                  "bf_buy_fax": "",
                  "bf_currencyValue": "人民币",
                  "bf_depositMoney": "12000",
                  "bf_balanceMoney": "13000",
                  "bf_commercialInvoice_num": 10,
                  "bf_fullInsurance_num": 10,
                  "bf_packageList_num": 10,
                  "bf_originCertificate_num": 10,
                  "bf_commercialInvoice_copy_num":10,
                  "bf_fullInsurance_copy_num": 10,
                  "bf_packageList_copy_num": 10,
                  "bf_originCertificate_copy_num": 10,
                  "bf_table1_totalQuantity": "22" ,
                  "bf_table1_totalAmount": "222.34",
                  "bf_table1_sayTotalAmount": "",

                  "bf_table1": [
                      {
                          "id": 65,
                          "createTime": 1528426522000,
                          "modifyTime": null,
                          "formInstId": 65,
                          "ftcId": 22,
                          "bf_table1_product": "hello",
                          "bf_table1_description": "ksjkjhkj",
                          "bf_table1_quantity": "10",
                          "bf_table1_price": "10.12",
                          "bf_table1_lineAmount": "101.20"
                      },
                      {
                          "id": 66,
                          "createTime": 1528426522001,
                          "modifyTime": null,
                          "formInstId": 65,
                          "ftcId": 22,
                          "bf_table1_product": "world",
                          "bf_table1_description": "xxxxx",
                          "bf_table1_quantity": "100",
                          "bf_table1_price": "10.12",
                          "bf_table1_lineAmount": "1012.00"
                      }
                  ],
                  "attachedFileList": []
              },
              "businessform_pi": {
                  "attachedFiles": [], 
                  "bp_countryOrigin": "中国China",
                  "bp_benCompany": "TIAN JIN FINANCIAL TRADE LINK IMPORT AND EXPORT CO.,LT",
                  "bp_AccountNo": "1000000010120100506972",
                  "bp_CompanyAddress": "NO.88-2-2205,HUANHE SOUTH ROAD,CHINA(TIANJIN)PILOT FREE TRADE ZONE TIANJIN AIRPORT ECONOMIC AREA),TIANJIN,CHINA",
                  "bp_bank": "CHINA ZHESHANG BANK BEIJING BRANCH", 	
                  "bp_bankAddress": "NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA",
                  "bp_swiftCode": "ZJCBCN2N", 	
                  "bp_countryAndManu": "China",
                  "bp_packing": "To be packed in standard packing",
                  "bp_insurance": "Without Insurance of the shipment by sea",
                  "bp_company": "ksjksjhk", 
                  "bp_no": "ksjhkdsjhkdhj", 
                  "bp_address": "ksjhkdjhkhj",
                  "bp_date": "ksjhkdjhkhj", 
                  "bp_portOfLoading": "skjgkdjhkjh", 
                  "bp_portOfDestination": "skjhlksjhkdhj", 
                  "bp_paymentTerm": "kdsnhkdjhkj", 
                  "bp_tradeTerm": "EXW", 
                  "bp_currencyValue": "人民币",
                  "bp_depositMoney": "1200", 
                  "bp_balanceMoney": "1300", 
                  "bp_table1_amount": "1400",
                  "bp_table1": [
                    {
                      "bp_table1_products": "skngksjhkh",
                      "bp_table1_hscode": "sjgksjghkj",
                      "bp_table1_description": "ksjgkjdhkj",
                      "bp_table1_quantity": "20",
                      "bp_table1_price": "22.22",
                      "bp_table1_lineAmount": "449.44"
                    },
                    {
                      "bp_table1_products": "skngksjhkh",
                      "bp_table1_hscode": "sjgksjghkj",
                      "bp_table1_description": "ksjgkjdhkj",
                      "bp_table1_quantity": "200",
                      "bp_table1_price": "22.22",
                      "bp_table1_lineAmount": "4490.44"
                    }
                  ]

              },
              "businessform_domestictradecontract": [
                  {
                      "attachedFiles": [], 
                      "bd_no": "xxxxxxxxxxxx", 
                      "bd_date": "sgsgsg", 
                      "bd_seller": "sgsgsg", 
                      "bd_sellerAddress": "sgsgsg", 
                      "bd_sellerTel": "6475758", 
                      "bd_sellerFax": "sgsgsgs", 
                      "bd_sellerEmail": "sgsgsgsgsg", 
                      "bd_sellerOptions": ["xxx", "yyy"],
                      "bd_currencyValue": "人民币",
                      "bd_ch_name": "sgsgsgsg",
                      "bd_ch_bankOfDeposit": "sgsgsgsg",
                      "bd_ch_account": "sgsgsgsg",
                      "bd_depositMoney": "12000", 
                      "bd_balanceMoney": "13000", 
                      "bd_table1_amount": "14000",
                      "bd_table1": [
                      {
                          "bd_table1_products": "jsjgsjgh",
                          "bd_table1_description": "sgjsgjsgh",
                          "bd_table1_quantity": "22",
                          "bd_table1_price": "22.22",
                          "bd_table1_lineAmount": "444.56"
                      },
                      {
                          "bd_table1_products": "jsjgsjgh",
                          "bd_table1_description": "sgjsgjsgh",
                          "bd_table1_quantity": "22",
                          "bd_table1_price": "22.22",
                          "bd_table1_lineAmount": "444.56"
                      }
                      ]
                  },
                  {
                      "attachedFiles": [], 
                      "bd_no": "sgsgsg", 
                      "bd_date": "sgsgsg", 
                      "bd_seller": "sgsgsg", 
                      "bd_sellerAddress": "sgsgsg", 
                      "bd_sellerTel": "6475758", 
                      "bd_sellerFax": "sgsgsgs", 
                      "bd_sellerEmail": "sgsgsgsgsg", 
                      "bd_sellerOptions": ["xxx", "yyy"],
                      "bd_currencyValue": "人民币",
                      "bd_ch_name": "sgsgsgsg",
                      "bd_ch_bankOfDeposit": "sgsgsgsg",
                      "bd_ch_account": "sgsgsgsg",
                      "bd_depositMoney": "12000", 
                      "bd_balanceMoney": "13000", 
                      "bd_table1_amount": "14000",
                      "bd_table1": [
                      {
                          "bd_table1_products": "jsjgsjgh",
                          "bd_table1_description": "sgjsgjsgh",
                          "bd_table1_quantity": "22",
                          "bd_table1_price": "22.22",
                          "bd_table1_lineAmount": "444.56"
                      },
                      {
                          "bd_table1_products": "jsjgsjgh",
                          "bd_table1_description": "sgjsgjsgh",
                          "bd_table1_quantity": "22",
                          "bd_table1_price": "22.22",
                          "bd_table1_lineAmount": "444.56"
                      }
                      ]
                  }
              ],
              "businessform_profitcalculation": {
                      "attachedFiles": [ ], 
                      "bpc_no": "sgsgsgs", 
                      "bpc_date": "2018-07-07", 
                      "bpc_buyerName": "sgsgsgsg", 
                      "bpc_buyerAddress": "sgsgsgsg", 
                      "bpc_buyerCreditLimt": "", 
                      "bpc_paymentRisk": "", 
                      "bpc_usedCreditLimit": "", 
                      "bpc_serviceCharge": "", 
                      "bpc_interest": "", 
                      "bpc_taxRefundRate": "", 
                      "bpc_finacialTime": "", 
                      "bpc_deposit": "", 
                      "bpc_balance": "", 
                      "bpc_finacialAmount": "", 
                      "bpc_item1Amount": "", 
                      "bpc_item2Amount": "", 
                      "bpc_item2C1": "", 
                      "bpc_item2C2": "1.16", 
                      "bpc_item2C3": "", 
                      "bpc_item3Amount": "", 
                      "bpc_item3C1": "", 
                      "bpc_item3C2": "", 
                      "bpc_item4Amount": "", 
                      "bpc_item4C1": "", 
                      "bpc_item4C2": "", 
                      "bpc_item4Note": "TCF service charge 2.2% of order amount", 
                      "bpc_item5Amount": "", 
                      "bpc_item5C1": "", 
                      "bpc_item5C2": "", 
                      "bpc_item5Note": "TCF offer 90 days of finance with 80% of the order amount", 
                      "bpc_item6Amount": "", 
                      "bpc_item6C1": "", 
                      "bpc_item6C2": "", 
                      "bpc_item6C3": "", 
                      "bpc_item6Note": "Charge 1.5% each month, with in total 3 months", 
                      "bpc_item7Amount": "", 
                      "bpc_item7C1": "", 
                      "bpc_item7C2": "", 
                      "bpc_item8Amount": "", 
                      "bpc_item8C1": "", 
                      "bpc_item8C2": "", 
                      "bpc_item8Note": "", 
                      "bpc_item9Amount": "", 
                      "bpc_item9C1": "", 
                      "bpc_item9C2": "", 
                      "bpc_item9C3": "", 
                      "bpc_item10Amount": "", 
                      "bpc_item10Note": "Overseas buyer should pay in 90 days;海外买家90天付款期限", 
                      "bpc_item11Amount": "", 
                      "bpc_item11C1": "", 
                      "bpc_item11C2": "", 
                      "bpc_item12Amount": "", 
                      "bpc_item13Amount": "", 
                      "bpc_item13C1": "", 
                      "bpc_item13C2": "", 
                      "bpc_item13Note": "TCF pay 20% deposit to factory 工厂定金支付20%", 
                      "bpc_item14Amount": "", 
                      "bpc_item14C1": "", 
                      "bpc_item14C2": "", 
                      "bpc_item14Note": "TCF will pay 80% before delivery工厂尾款支付80%", 
                      "bpc_table1": [
                          {
                              "bpc_table1_products": "sgsgsg", 
                              "bpc_table1_hscode": "sgsgsgsg", 
                              "bpc_table1_taxrate": 10
                          },
                          {
                              "bpc_table1_products": "sgsgsg", 
                              "bpc_table1_hscode": "sgsgsgsg", 
                              "bpc_table1_taxrate": 20
                          }
                      ], 
                      "bpc_deliveryTime": "2018-04-05", 
                      "bpc_shipping": "sgsgsg", 
                      "bpc_agentCompany": "sgsgsg", 
                      "bpc_agentContactTo": "sgsgsgsg", 
                      "bpc_agentEmail": "sgsgsgsg", 
                      "bpc_agentMobile": "23445", 
                      "bpc_beneficiary": "BIZOE INTERNATIONAL GROUP LIMITED", 
                      "bpc_companyAddress": "UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL", 
                      "bpc_beneficiaryBankName": "CHINA ZHESHANG BANK BEIJING BRANCH", 
                      "bpc_bankAccount": "NRA1000000011420100046799", 
                      "bpc_bankAddress": "NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA", 
                      "bpc_swiftBic": "ZJCBCN2N"
              },

              "businessform_depositpay": {
                  "bdp_no": "sgsgsg", 
                  "bdp_date": "2018-08-07", 
                  "bdp_buyerName": "sgsgsg", 
                  "bdp_buyerAddress": "sgsgsg", 
                  "bdp_table1": [
                      {
                          "bdp_table1_item": "sgsgsg", 
                          "bdp_table1_desc": "sgsgsg", 
                          "bdp_table1_lineAmount": "20"
                      },
                      {
                          "bdp_table1_item": "sgsgsg", 
                          "bdp_table1_desc": "sgsgsg", 
                          "bdp_table1_lineAmount": "200"
                      }
                  ], 
                  "bdp_table1_amount": "220", 
                  "bdp_beneficiary": "BIZOE INTERNATIONAL GROUP LIMITED", 
                  "bdp_companyAddress": "UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL", 
                  "bdp_beneficiaryBankName": "CHINA ZHESHANG BANK BEIJING BRANCH", 
                  "bdp_bankAccount": "NRA1000000011420100046799", 
                  "bdp_bankAddress": "NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA", 
                  "bdp_swiftBic": "ZJCBCN2N"
              },

              "businessform_paymentnotice" :{
                  "bpn_no": "djhjdshjksh", 
                  "bpn_date": "2018-08-07", 
                  "bpn_buyerName": "sgsgsg", 
                  "bpn_buyerAddress": "sgsgsgsg", 
                  "bpn_table1": [
                      {
                          "bpn_table1_product": "sgsgsgsg", 
                          "bpn_table1_description": "sgsgsgsg", 
                          "bpn_table1_price": "22.12", 
                          "bpn_table1_quantity": "22", 
                          "bpn_table1_lineAmount": "3333"
                      },
                      {
                          "bpn_table1_product": "sgsgsgsg", 
                          "bpn_table1_description": "sgsgsgsg", 
                          "bpn_table1_price": "22.12", 
                          "bpn_table1_quantity": "22", 
                          "bpn_table1_lineAmount": "3333"
                      }
                  ], 
                  "bpn_table1_amount": "2000", 
                  "bpn_depositMoney": "222", 
                  "bpn_balanceMoney": "3333", 
                  "bpn_paidDeposit": "90", 
                  "bpn_unpaidBalance": "90", 
                  "bpn_payDeadline": "sgsgsgsg", 
                  "bpn_beneficiary": "BIZOE INTERNATIONAL GROUP LIMITED", 
                  "bpn_companyAddress": "UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL", 
                  "bpn_beneficiaryBankName": "CHINA ZHESHANG BANK BEIJING BRANCH", 
                  "bpn_bankAccount": "NRA1000000011420100046799", 
                  "bpn_bankAddress": "NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA", 
                  "bpn_swiftBic": "ZJCBCN2N"
              },

              "formInstId": 65,
              "flowId": 1,
              "formId": 1,
              "formServiceName": "business_lading",
              "bindingFormInstId": null,
              "orderCode": "NO.DD2018060800240",
              "approvals": [],
              "relationFormInst": {
                  "id": 65,
                  "createTime": 1528426522000,
                  "modifyTime": 1529475442000,
                  "formId": 1,
                  "flowName": "业务提单（生成订单）",
                  "flowId": 1,
                  "formInstName": null,
                  "createUserName": "刘薇",
                  "createUserId": 5,
                  "bindingFormInstId": null,
                  "orderCode": "NO.DD2018060800240",
                  "ftcCode": "",
                  "dtcCode": "",
                  "buyerName": "",
                  "relationFormInstId": 65,
                  "flowPath": "businessform",
                  "formServiceName": "business_lading",
                  "formInstStatus": 0
              },
              "role": [
                  {
                      "id": 1,
                      "createTime": 1525752204000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "businessform_businesscheckform",
                      "permission": "W"
                  },
                  {
                      "id": 2,
                      "createTime": 1525752204000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "businessform_foreigntradecontract",
                      "permission": "W"
                  },
                  {
                      "id": 3,
                      "createTime": 1525752204000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "businessform_pi",
                      "permission": "W"
                  },
                  {
                      "id": 4,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "businessform_domestictradecontract",
                      "permission": "W"
                  },
                  {
                      "id": 5,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "businessform_profitcalculation",
                      "permission": "W"
                  },
                  {
                      "id": 6,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "item01_01",
                      "permission": "R"
                  },
                  {
                      "id": 7,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "item01_02",
                      "permission": "R"
                  },
                  {
                      "id": 8,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "item01_03",
                      "permission": "R"
                  },
                  {
                      "id": 9,
                      "createTime": 1525752205000,
                      "modifyTime": null,
                      "formId": 1,
                      "flowId": 1,
                      "flowNodeId": 1,
                      "flowNodeName": "业务填报合同信息",
                      "itemName": "item01_04",
                      "permission": "R"
                  }
              ]
            };
            */


            /**
             * 处理后端返回的空数组的情况
             */

            if (data.businessform_businesscheckform.bb_table1.length === 0){
              data.businessform_businesscheckform.bb_table1 = [{
                  bb_productName: "", 
                  bb_productFunction: "", 
                  bb_productUse: "", 
                  bb_hasBrand: "", 
                  bb_productCode: "", 
                  bb_exportCountry: "", 
                  bb_qualification: "", 
                  bb_needCheck: "", 
                  bb_otherNeed: "" 
              }];
            }


            data.businessform_domestictradecontract.forEach((e) => {
              if (e.bd_table1.length === 0){
                e.bd_table1 = [{
                  bd_table1_products: "",
                  bd_table1_description: "",
                  bd_table1_quantity: "",
                  bd_table1_price: "",
                  bd_table1_lineAmount: "",
                }];
              }
            });

            if (data.businessform_foreigntradecontract.bf_table1.length === 0) {
                data.businessform_foreigntradecontract.bf_table1 = [{
                  bf_table1_product: "",
                  bf_table1_description: "", 
                  bf_table1_price: "", 
                  bf_table1_lineAmount: "", 
                  bf_table1_quantity: "" 
                }];
            }

            if (data.businessform_pi.bp_table1.length === 0) {
                data.businessform_pi.bp_table1  = [{
                  bp_table1_products: '',
                  bp_table1_hscode: '',
                  bp_table1_description: '',
                  bp_table1_quantity: '',
                  bp_table1_price: '',
                  bp_table1_lineAmount: '',
                }];
            }


            if (data.businessform_depositpay.bdp_table1.length === 0) {
                data.businessform_depositpay.bdp_table1  = [{
                  bdp_table1_item: '',
                  bdp_table1_desc: '',
                  bdp_table1_lineAmount: '',
                }];
            }

            if (data.businessform_paymentnotice.bpn_table1.length === 0) {
                data.businessform_paymentnotice.bpn_table1  = [{
                  bpn_table1_product: '',
                  bpn_table1_description: '',
                  bpn_table1_price: '',
                  bpn_table1_quantity: '',
                  bpn_table1_lineAmount: ''
                }];
            }

            if (data.businessform_paymentnotice.bpn_table1.length === 0) {
                data.businessform_paymentnotice.bpn_table1  = [{
                  bpn_table1_product: '',
                  bpn_table1_description: '',
                  bpn_table1_price: '',
                  bpn_table1_quantity: '',
                  bpn_table1_lineAmount: ''
                }];
            }

            //对其中的字符串类型的附件名称，进行分割
            data = JSON.parse(
              JSON.stringify(data)
                .replace(/(attachedFiles)/g, function() {
                  return "useless01";
                })
                .replace(/(attachedFileList)/g, function() {
                  return "attachedFiles";
                })
                .replace(/(relationFormInst)/g, function() {
                  return "relationFormInstId";
                }),
              function(k, v) {
                if (k === "attachedFiles") {
                  if (Array.isArray(v)) {
                    return v.map(e => {
                      return {
                        name: e.realFileName,
                        status: 1,
                        id: e.id
                      };
                    });
                  } else {
                    return [];
                  }
                }

                if (k === "relationFormInstId") {
                  if (_.isPlainObject(v)) {
                    return [v];
                  } else {
                    return [];
                  }
                }

                return v;
              }
            );

            for (const key in data) {
              vm.$set(vm.saveData, key, data[key]);
            }

            for (
              let i = 0,len = vm.saveData.businessform_domestictradecontract.length - 1;i < len;i++) {
              //考虑有多个内贸合同
              //this.onlyAddTab()，根据个数决定调用 n - 1 次, 添加tab
              vm.onlyAddTab();
            }

            let approvalIndex,
              approvalFullName,
              names = [], originApprovals = _.cloneDeep(vm.saveData.originApprovals);

            if (data.role) {
              data.role.forEach(e => {
                if (e.itemName.indexOf("item") === -1) {
                  vm.$set(vm.editRoles, e.itemName, e.permission);
                } else {
                  let num = Number(e.itemName[e.itemName.length - 1]) - 1;
                  if (e.permission == "W") {
                    approvalIndex = num;
                    approvalFullName = e.itemName;
                  }
                }
              });

              vm.editable =
                vm.editRoles.businessform_businesscheckform == "W"
                  ? true
                  : false;
              vm.saveAndSend = true;


              let copyApprovals = _.cloneDeep(data.approvals);

              if (approvalIndex !== undefined) {
                if (approvalIndex >= 0) {
                  for (let i = 0; i <= approvalIndex; i++) {
                    if (copyApprovals[i]) {
                      for (var prop in originApprovals[i]) {
                        if (
                          prop != "rw" &&
                          prop != "approval_div_name" &&
                          prop != "item"
                        ) {
                          originApprovals[i][prop] =
                            copyApprovals[i][prop];
                        }
                      }
                      originApprovals[i].approval_id =
                        "" + copyApprovals[i].id;
                    }
                  }
                }


                let date = new Date();
                originApprovals[approvalIndex].rw = "W";
                originApprovals[approvalIndex].approval_time =
                  date.toLocaleDateString() +
                  " " +
                  date.toTimeString().slice(0, 9);
                originApprovals[approvalIndex].approval_username = JSON.parse(getStore("userMsg")).userName;
              } else if (copyApprovals.length > 0) {
                for (let i = 0; i < copyApprovals.length; i++) {
                  for (var prop in originApprovals[i]) {
                    if (
                      prop != "rw" &&
                      prop != "approval_div_name" &&
                      prop != "item"
                    ) {
                      originApprovals[i][prop] =
                        copyApprovals[i][prop];
                    }
                  }
                  originApprovals[i].approval_id =
                    "" + copyApprovals[i].id;
                }
              }

              vm.$set(vm.saveData, "originApprovals", originApprovals);
              vm.$set(vm.saveData, "isSalesMan", false);
              vm.$set(vm.saveData, "businessform_no", data.orderCode);
            } else {
              vm.$set(vm.saveData, "isSalesMan", true);
            }

            getSendMenus(params).then(response => {
              vm.sendMenus = response.data.datas[0];
              vm.allData = _.cloneDeep(vm.saveData);
            });
          });
        }
      }

    });
  },
  beforeRouteLeave(to, from, next) {
    document.querySelector(".initiatingprocess  .routers-ctrl").style.zIndex =
      "-1";
    if (getStore("flow1-save-status") === 'unsave') {
      this.$confirm("您填写的内容尚未保存或发送,是否要离开?", "提示", {
        confirmButtonText: "离开",
        cancelButtonText: "留下",
        type: "warning"
      })
        .then(() => {
          next();
        })
        .catch(() => {
          Array.prototype.forEach.call(
            document.getElementsByTagName("*"),
            e => {
              e.blur();
            }
          );
          next(false);
        });
    } else {
      next();
    }
  },

  beforeDestroy(){
    setStore("flow1-save-status", "unsave");
  },
  data() {
    return {
      saveData: {
        //业务提单中所有表都会显示的订单号
        businessform_no: "",

        hasSaved: false,

        //业务员填写流程
        isSalesMan: true,

        newApprovalName: "",

        approvalNames: [
          "单证员审批合同信息",
          "业务领导审批合同信息",
          "风控员审批合同信息",
          "财务审批合同信息"
        ],

        newApproval: {
          approval_opinion: "",
          approval_username: "",
          approval_time: "",
          approval_div_name: ""
        },

        prevApprovals: [],

        remainApprovals: [],

        //该流程中的所有审批项
        originApprovals: [
          {
            approval_opinion: "",
            approval_username: "",
            approval_time: "",
            approval_div_name: "单证员审批合同信息",
            rw: "R",
            item: "item_01_01"
          },
          {
            approval_opinion: "",
            approval_username: "",
            approval_time: "",
            approval_div_name: "业务领导审批合同信息",
            rw: "R",
            item: "item_01_02"
          },
          {
            approval_opinion: "",
            approval_username: "",
            approval_time: "",
            approval_div_name: "风控员审批合同信息",
            rw: "R",
            item: "item_01_03"
          },
          {
            approval_opinion: "",
            approval_username: "",
            approval_time: "",
            approval_div_name: "财务审批合同信息",
            rw: "R",
            item: "item_01_04"
          }
        ],

        relationFormInstId: [],

        //业务审核单
        businessform_businesscheckform: {
          id: '',
          formInstId: '',
          attachedFiles: [], //票据附件
          bb_table1: [
            {
              bb_productName: "", //产品名称
              bb_productFunction: "", //产品用途
              bb_productUse: "", //产品用途
              bb_hasBrand: "", //产品是否有品牌
              bb_productCode: "", //产品HS编码
              bb_exportCountry: "", //出口国家
              bb_qualification: "", //工厂资质
              bb_needCheck: "", //是否需要商检
              bb_otherNeed: "" //其他需求
            }
          ]
        },

        //外贸合同
        businessform_foreigntradecontract: {
          id: '',
          formInstId: '',
          attachedFiles: [], //票据附件
          bf_orderNumber: "", //订单编号
          bf_orderDate: "", //订单日期
          bf_tradeTerm: "", //成交方式
          bf_shippingMarks: "", //唛头
          bf_delivery: "", //交货期
          bf_portOfLoad: "", //装运港
          bf_portOfDestination: "", //目的港
          bf_shipment: "", //运输
          bf_downPaymentRate: "", //定金比例
          bf_downPayment: "", //定金
          bf_symbol: ["√", "×"],

          bf_buy_nameOptions: ["xxx", "yyy"],

          bf_currencyValue: "人民币",

          //单据要求
          bf_commercialInvoice: "", //商业发票
          bf_fullForm: "", //全套提单
          bf_airParcel: "", //空运
          bf_fullInsurance: "", //全套保险单据
          bf_packageList: "", //装箱单
          bf_originCertificate: "", //原产地证

          //份数
          bf_commercialInvoice_num: 0,
          bf_fullInsurance_num: 0,
          bf_packageList_num: 0,
          bf_originCertificate_num: 0,

          //copies
          bf_commercialInvoice_copy_num: 0,
          bf_fullInsurance_copy_num: 0,
          bf_packageList_copy_num: 0,
          bf_originCertificate_copy_num: 0,

          //买家信息
          bf_buy_name: "", //买方
          bf_buy_address: "", //买方地址
          bf_buy_tel: "", //电话
          bf_buy_email: "", //邮箱
          bf_buy_fax: "", //传真

          bf_table1_totalQuantity: 0 ,//新增
          bf_table1_totalAmount: 0 ,//新增
          bf_table1_sayTotalAmount: '' ,//新增

          bf_depositMoney: 0, //定金
          bf_balanceMoney: 0, //尾款

          //有一个表格
          bf_table1: [
            {
              bf_table1_product: "", //产品
              bf_table1_description: "", //产品描述
              bf_table1_price: "", //价格
              bf_table1_lineAmount: "", //一行的金额,
              bf_table1_quantity: "" //一行数量
            }
          ]
        },

        //PI
        businessform_pi: {
          id: '',
          formInstId: '',
          attachedFiles: [], //票据附件

          bp_countryOrigin: '中国China',
          bp_benCompany: 'TIAN JIN FINANCIAL TRADE LINK IMPORT AND EXPORT CO.,LTD	',
          bp_AccountNo: '1000000010120100506972',
          bp_CompanyAddress: 'NO.88-2-2205,HUANHE SOUTH ROAD,CHINA(TIANJIN)PILOT FREE TRADE ZONE TIANJIN AIRPORT ECONOMIC AREA),TIANJIN,CHINA	',
          bp_bank: 'CHINA ZHESHANG BANK BEIJING BRANCH', 	
          bp_bankAddress: 'NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA',
          bp_swiftCode: 'ZJCBCN2N', 	
          bp_countryAndManu: 'China', //原产地
          bp_packing: 'To be packed in standard packing',
          bp_insurance: 'Without Insurance of the shipment by sea',



          //pi 头部信息
          bp_company: '', // 公司
          bp_no: '', //编号
          bp_address: '', //地址
          bp_date: '', //日期


          bp_portOfLoading: '', //出港地址
          bp_portOfDestination: '', //目的港
          bp_paymentTerm: '', //付款方式,
          bp_tradeTerm: 'EXW', //成交方式

          bp_currencyValue: '人民币',

          bp_depositMoney: 0, //定金
          bp_balanceMoney: 0, //

          bp_table1_amount: 0,
          //一个表格
          bp_table1: [
            {
              bp_table1_products: '',
              bp_table1_hscode: '',
              bp_table1_description: '',
              bp_table1_quantity: '',
              bp_table1_price: '',
              bp_table1_lineAmount: '',
            }]
          },

        //内贸合同
        businessform_domestictradecontract: [
          {
           id: '',
           formInstId: '',
            attachedFiles: [], //票据附件
            //合同头部信息
            bd_no: "", //编号
            bd_date: "", //日期
            bd_seller: "", //卖方
            bd_sellerAddress: "", //卖方地址
            bd_sellerTel: "", //卖方电话
            bd_sellerFax: "", //卖方传真
            bd_sellerEmail: "", //卖方邮箱

            bd_sellerOptions: ["xxx", "yyy"],

            bd_currencyValue: "人民币",

            //卖方开户行信息，中文版
            bd_ch_name: "",
            bd_ch_bankOfDeposit: "",
            bd_ch_account: "",

            bd_depositMoney: 0, //定金
            bd_balanceMoney: 0, //尾款

            bd_table1_amount: 0,
            bd_table1: [
              {
                bd_table1_products: "",
                bd_table1_description: "",
                bd_table1_quantity: "",
                bd_table1_price: "",
                bd_table1_lineAmount: "",
              }
            ]
          }
        ],

        //利润测算
        businessform_profitcalculation: {
          id: '',
          formInstId: '',
          attachedFiles: [], //票据附件
          bpc_no: '', //编号

          bpc_date: '', //日期
          bpc_buyerName: '',
          bpc_buyerAddress: '',

          bpc_buyerCreditLimt: '',
          bpc_paymentRisk: '',
          bpc_usedCreditLimit: '',
          bpc_serviceCharge:'',
          bpc_interest: '',
          bpc_taxRefundRate: '',
          bpc_finacialTime: '',
          bpc_deposit: '',
          bpc_balance: '',
          bpc_finacialAmount: '',

          bpc_usedCreditLimit_currency:'$',
          bpc_detail_currency1: '￥' ,
          bpc_detail_currency2: '￥',
          bpc_detail_currency3: '￥',
          bpc_detail_currency4: '￥',
          bpc_detail_currency5: '￥',
          bpc_detail_currency6: '￥',


          //Factory Price with VAT 
          bpc_item1Amount: '',


          //Tax refund 
          bpc_item2Amount: '',
          bpc_item2C1: '',
          bpc_item2C2: '1.16',
          bpc_item2C3: '',

        
          // original order amount after reduce the tax refund
          bpc_item3Amount: '',
          bpc_item3C1: '',
          bpc_item3C2: '',


          //Comission of TCF
          bpc_item4Amount: '',
          bpc_item4C1: '',
          bpc_item4C2: '',
          bpc_item4Note: 'TCF service charge 2.2% of order amount',

          //Financial amount by TCF
          bpc_item5Amount: '',
          bpc_item5C1: '',
          bpc_item5C2: '',
          bpc_item5Note: 'TCF offer 90 days of finance with 80% of the order amount',


          // Financial interest 
          bpc_item6Amount: '',
          bpc_item6C1: '',
          bpc_item6C2: '',
          bpc_item6C3: '',
          bpc_item6Note: 'Charge 1.5% each month, with in total 3 months',

          // Total Service charge of TCF
          bpc_item7Amount: '',
          bpc_item7C1: '',
          bpc_item7C2: '',
          
          // Sales contract amount 
          bpc_item8Amount: '',
          bpc_item8C1: '',
          bpc_item8C2: '',
          bpc_item8Note: '',


          //Deposit
          bpc_item9Amount: '',
          bpc_item9C1: '',
          bpc_item9C2: '',
          bpc_item9C3: '',

          // Balance pay to TCF
          bpc_item10Amount: '',
          bpc_item10Note: 'Overseas buyer should pay in 90 days;海外买家90天付款期限',

            //Warranty money
          bpc_item11Amount: '',
          bpc_item11C1: '',
          bpc_item11C2: '',


          // Purchase contract amount
          bpc_item12Amount: '',

          // deposit
          bpc_item13Amount: '',
          bpc_item13C1: '',
          bpc_item13C2: '',
          bpc_item13Note: 'TCF pay 20% deposit to factory 工厂定金支付20%',


          // Balance
          bpc_item14Amount: '',
          bpc_item14C1: '',
          bpc_item14C2: '',
          bpc_item14Note: 'TCF will pay 80% before delivery工厂尾款支付80%',

          bpc_table1: [{
          bpc_table1_products: '',
          bpc_table1_hscode: '',
          bpc_table1_taxrate: 0
          }],

          bpc_deliveryTime: '', //发货时间
          bpc_shipping: '',//
          bpc_agentCompany: '',
          bpc_agentContactTo: '',
          bpc_agentEmail: '',
          bpc_agentMobile: '',


          bpc_beneficiary: 'BIZOE INTERNATIONAL GROUP LIMITED',
          bpc_companyAddress: 'UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL',
          bpc_beneficiaryBankName: 'CHINA ZHESHANG BANK BEIJING BRANCH',
          bpc_bankAccount:'NRA1000000011420100046799',
          bpc_bankAddress: 'NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA',
          bpc_swiftBic:'ZJCBCN2N',
        },

        //定金付款
        businessform_depositpay: {
          id: '',
          formInstId: '',
          bdp_no: '',
          bdp_date: '',
          bdp_buyerName: '',
          bdp_buyerAddress: '',

          bdp_table1: [{
              bdp_table1_item: '',
              bdp_table1_desc: '',
              bdp_table1_lineAmount: '',
          }],

          bdp_table1_amount: '',

          bdp_beneficiary: 'BIZOE INTERNATIONAL GROUP LIMITED',
          bdp_companyAddress: 'UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL',
          bdp_beneficiaryBankName: 'CHINA ZHESHANG BANK BEIJING BRANCH',
          bdp_bankAccount:'NRA1000000011420100046799',
          bdp_bankAddress: 'NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA',
          bdp_swiftBic:'ZJCBCN2N'
        }, 
        //付款通知
        businessform_paymentnotice:{
          id: '',
          formInstId: '',
          bpn_no: '',
          bpn_date: '',
          bpn_buyerName: '',
          bpn_buyerAddress: '',

          bpn_table1: [{
              bpn_table1_product: '',
              bpn_table1_description: '',
              bpn_table1_price: '',
              bpn_table1_quantity: '',
              bpn_table1_lineAmount: ''
          }],

          bpn_table1_amount: '',

          bpn_depositMoney: 0, //定金
          bpn_balanceMoney: 0, //尾款

          bpn_paidDeposit: 0, //已支付货款
          bpn_unpaidBalance: 0, //未支付
          bpn_payDeadline: '', //支付日期

        

          bpn_beneficiary: 'BIZOE INTERNATIONAL GROUP LIMITED',
          bpn_companyAddress: 'UNIT 04,7/F BRIGHT WAY TOWER NO.33 MONG KOK RD KL',
          bpn_beneficiaryBankName: 'CHINA ZHESHANG BANK BEIJING BRANCH',
          bpn_bankAccount:'NRA1000000011420100046799',
          bpn_bankAddress: 'NO.1 FINANCIAL STEREET,XICHENG DISTRICT,BEIJING,CHINA',
          bpn_swiftBic:'ZJCBCN2N',
        },

      },
      allData: {},
      bus: null,
      editRoles: {
        businessform_businesscheckform: "W",
        businessform_foreigntradecontract: "W",
        businessform_pi: "W",
        businessform_domestictradecontract: "W",
        businessform_profitcalculation: "W",
        businessform_paymentnotice: "W",
        businessform_depositpay: "W"
      },
      sendMenus: [],
      isShowItem: false,
      isShowSpan: false,
      editableTabsValue: "1",
      editable: true,
      saveAndSend: true,
      process: ["待发事项", "待办事项", "已办事项", "发起流程"],
      processNumber: 3,
      addStartName: 7,
      editableTabsFixed: [
        {
          title: "业务审核表",
          name: "1",
        },
        {
          title: "外贸合同",
          name: "2",
        },
        {
          title: "PI",
          name: "3",
        },
        {
          title: "内贸合同",
          name: "4",
        },
        {
          title: "利润测算表",
          name: "100",
        },
        {
          title: "保证金付款发票",
          name: "101",
        },
         {
          title: "付款通知单",
          name: "102",
        }
      ],
    };
  },
  props: {
  },
  components: {
    businessCheckForm,
    profitCalculation,
    foreignTradeContract,
    pi,
    domesticTradeContract,
    depositPay,
    paymentNotice,
    fixedForm
  },
  methods: {

    /**
     * 其他子组件的数据发生改变时，及时更新
     * @param {String} key 修改所有数据中对应的合同
     * @param {Object} value  合同对应的值
     */
    updateData(key, value) {
      let temp = _.cloneDeep(this.allData);
      temp[key] = value;
      this.allData = temp;
    },

    /**
     * 更新多个内贸合同
     * @param {String} key 内贸合同
     * @param {Number } index 内贸合同中对应的索引
     * @param {Object} value  合同对应的值
     */
    updateDCData(key, index, value) {

      let temp = _.cloneDeep(this.allData);
      temp[key].splice(index, 1, value);
      this.allData = temp;
    },

    onlyAddTab() {
      //解决从server获得数据时，内贸合同有数据但是没tab的问题
      let tempLen = this.editableTabsFixed.length;
      this.editableTabsFixed.splice(tempLen - 3, 0, {
        title: "内贸合同",
        formId: "domestictradecontract",
        name: "" + this.addStartName
      });
      this.addStartName++;
    },
    addTab() {

      //添加内贸合同
      let tempLen = this.editableTabsFixed.length;
      this.editableTabsFixed.splice(tempLen - 3, 0, {
        title: "内贸合同",
        name: "" + this.addStartName
      });

      this.addStartName++;

      let newDtc = _.cloneDeep(this.allData.businessform_domestictradecontract[0]);
      let len = this.allData.businessform_domestictradecontract.length;

      newDtc.bd_no = newDtc.bd_no.replace(/-(\d+)$/, function(match, p1) {
        // let n = Number(p1) + 1;
        return "-" + (len + 1);
      });

      let oldDtcs = _.cloneDeep(this.allData.businessform_domestictradecontract);
      oldDtcs.push(newDtc);

      this.$set(this.saveData, "businessform_domestictradecontract", oldDtcs);

      let temp = _.cloneDeep(this.allData);
      temp.businessform_domestictradecontract = oldDtcs;
      this.allData = temp;
    },

    removeTab(index) {
      //移除内贸合同
      this.editableTabsFixed.splice(index, 1);
      let oldDtcs = _.cloneDeep(this.allData.businessform_domestictradecontract);
      oldDtcs.splice(index - 5,  1);
      
      this.$set(this.saveData, "businessform_domestictradecontract", oldDtcs);

      let temp = _.cloneDeep(this.allData);
      temp.businessform_domestictradecontract = oldDtcs;
      this.allData = temp;

      setTimeout(function() {
        let allTabs = document.querySelectorAll(".businessform div[role=tab]");
        allTabs[allTabs.length - 1].click();
      }, 0);
    },
    clickTabs(curTab) {
    },
    specialInitialProcess(event) {
      let cls = event.target.classList;
      if (
        cls.contains("el-icon-arrow-right") &&
        cls.contains("el-breadcrumb__separator")
      ) {
        return;
      }

      let dom = document.querySelector(".initiatingprocess .routers-ctrl");
      if (dom) {
        dom.style.zIndex = "0";
      }
    }
  }
};
</script>


<style lang="scss">
.businessform {
  padding: 20px;

  i.el-breadcrumb__separator {
    margin: 0 !important;
  }

  i.el-breadcrumb__separator[class*="icon"] {
    margin: 0 !important;
    padding: 0 9px !important;
  }

  .operation-icon {
    position: absolute;
    right: 3px;
    top: 50%;
    transform: translate(0, -50%);
  }

  .businessform-fixed {
    border: 1px solid #999;
    margin-top: 20px;
  }
}
</style>
